<script>

import * as echarts from 'echarts';
// import $ from 'jquery'
export default {
  name: 'VisualizationTwo',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data2', {}).then(res => {
        if (res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          for (let i = 0; i < res.data.data.length; i++) {
            data1.push(
                res.data.data[i].param1
            );
            data2.push(
                res.data.data[i].param2
            );
          }
          this.init(data1, data2)
        }
      }).catch(error => {
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data1, data2) {
      var chartDom = document.getElementById('main2');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        color: ["#8782d6"],
        title: {
          text: '民宿价格统计'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          },
          formatter: '价格: {b} 元 <br/> 数量: {c} 个' // {a}（系列名称），{b}（数据项名称），{c}（数值）, {d}（百分比）
        },
        // legend: {
        //   data: ['价格']
        // },
        // toolbox: {
        //   feature: {
        //     saveAsImage: {}
        //   }
        // },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            name: "价格",
            type: 'category',
            boundaryGap: false,
            data: data1
          }
        ],
        yAxis: [
          {
            name: "数量",
            type: 'value'
          }
        ],
        series: [
          {
            name: '价格',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: data2
          }
        ]
      };

      option && myChart.setOption(option);

    }
  }

}
</script>

<template>
  <div id="main2"></div>
</template>

<style scoped>
#main2 {
  width: 100%;
  height: 100%;
}
</style>